package com.jike.noobmoney.mvp.view.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.adapter.ShouZhiAdapter;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.ShouZhiChannelEntity;
import com.jike.noobmoney.mvp.view.fragment.ShouZhiFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Create by xuke on 2018/11/10
 * 收支明细
 */
public class ShouZhiActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.channelTab)
    TabLayout channelTab;
    @BindView(R.id.viewpger)
    ViewPager viewpger;

    private List<ShouZhiChannelEntity> tabNameList = new ArrayList<>();
    private List<Fragment> newsFragmentList = new ArrayList<>();


    public static void startAction(Context context, int type) {
        Intent intent = new Intent(context, ShouZhiActivity.class);
        intent.putExtra(ConstantValue.IntentKey.KEY_FROM_TYPE, type);
        context.startActivity(intent);
    }
    /**
     * 如果要全屏,重写这个方法返回false
     */
    public Boolean isfits() {
        return true;
    }

    /**
     * 如果要白色主题,重写这个方法返回false
     */
    public boolean ismain() {
        return true;
    }

    @Override
    protected int layoutResID() {
        return R.layout.activity_shou_zhi;
    }

    @Override
    protected void initData() {
        tvTitle.setText("现金明细");
        int tab = getIntent().getIntExtra(ConstantValue.IntentKey.KEY_FROM_TYPE, 0);

        tabNameList.add(new ShouZhiChannelEntity("任务", "1"));
        tabNameList.add(new ShouZhiChannelEntity("好友", "2"));
        tabNameList.add(new ShouZhiChannelEntity("提现", "3"));
        //tabNameList.add(new ShouZhiChannelEntity("签到", "6"));
        //tabNameList.add(new ShouZhiChannelEntity("充值", "7"));
        //tabNameList.add(new ShouZhiChannelEntity("消费", "8"));

        for (int i = 0; i < tabNameList.size(); i++) {
            ShouZhiFragment newsListFragment = new ShouZhiFragment();
            Bundle bundle = new Bundle();
            bundle.putString(ShouZhiFragment.Channels, tabNameList.get(i).getStatus());
            newsListFragment.setArguments(bundle);
            newsFragmentList.add(newsListFragment);
            channelTab.addTab(channelTab.newTab().setText(tabNameList.get(i).getTitle()));

        }

        ShouZhiAdapter adapter = new ShouZhiAdapter(getSupportFragmentManager(), tabNameList, newsFragmentList);
        viewpger.setOffscreenPageLimit(newsFragmentList.size());
        viewpger.setAdapter(adapter);
        channelTab.setupWithViewPager(viewpger);
        viewpger.setCurrentItem(tab);

    }


    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
